/*
 * @Description:
 * @Author:
 * @Date: 2024-10-17 23:10:20
 * @LastEditTime: 2025-02-16 17:01:32
 * @LastEditors: XXX
 */
import type { AppState, AppStore } from '@/store/modules/app'
import type { PermissionState, PermissionStore } from '@/store/modules/permission'
import type { SettingState, SettingStore } from './modules/settings'
import type { UserState, UserStore } from './modules/user'
import type { TagsViewState, TagsStore } from './modules/tagsview'

import { createStore, createLogger } from "vuex"
import { store as app } from '@/store/modules/app'
import { store as permission } from '@/store/modules/permission'
import { store as setting } from '@/store/modules/settings'
import { store as user } from '@/store/modules/user'
import { store as tagsView } from '@/store/modules/tagsview'

export interface RootState {
  app: AppState
  permission: PermissionState
  setting: SettingState,
  user: UserState,
  tagsView: TagsViewState
}

// Plug in logger when in development environment
const debug = process.env.NODE_ENV !== 'production'
const plugins = debug ? [createLogger({})] : []

export type Store =
  AppStore<Pick<RootState, 'app'>>
  & PermissionStore<Pick<RootState, 'permission'>>
  & SettingStore<Pick<RootState, 'setting'>>
  & UserStore<Pick<RootState, 'user'>>
  & TagsStore<Pick<RootState, 'tagsView'>>

export const store = createStore({
  modules: {
    app,
    permission,
    setting,
    user,
    tagsView
  }
})

export function useStore (): Store {
  return store as Store
}
